package com.dynamicthreadpool.strategy;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * CallerRunsPolicy拒绝策略实现
 * 调用者的线程（提交任务的线程）会执行该任务
 */
public class CallerRunsPolicy implements RejectStrategy {

    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        if (!executor.isShutdown()) {
            // 直接在调用者线程中执行任务
            r.run();
        }
    }

    @Override
    public String getPolicyName() {
        return "callerruns";
    }
}
